const axios = require('axios');

(async () => {
  try {
    // 1. 登录
    const loginResponse = await axios.post('http://localhost:3000/api/auth/login', {
      email: 'admin@campus.com',
      password: 'admin123'
    });
    
    const authToken = loginResponse.data.token;
    console.log('✅ 登录成功');
    
    // 2. 获取可获得勋章（添加时间戳避免缓存）
    const timestamp = Date.now();
    const response = await axios.get(`http://localhost:3000/api/badges?filter=available&t=${timestamp}`, {
      headers: { Authorization: `Bearer ${authToken}` }
    });
    
    console.log(`📊 API返回数量: ${response.data.badges.length}`);
    
    // 3. 检查每个勋章的状态
    let availableCount = 0;
    let mintedCount = 0;
    
    response.data.badges.forEach(badge => {
      if (badge.status === 'available') {
        availableCount++;
      } else if (badge.status === 'minted') {
        mintedCount++;
        console.log(`⚠️ 发现minted勋章: ${badge.badge_name} (活动${badge.activity_id})`);
      }
    });
    
    console.log(`✅ 状态为available的勋章: ${availableCount}`);
    console.log(`❌ 状态为minted的勋章: ${mintedCount}`);
    
    if (mintedCount === 0) {
      console.log('🎉 可获得勋章筛选正确！');
    } else {
      console.log('❌ 可获得勋章筛选有问题');
    }
    
  } catch (error) {
    console.error('测试失败:', error.message);
  }
})(); 